package ui.maps
{
	import common.model.DcGpsReal;
	import common.model.WqDepInfo;
	import common.model.WqPlanLocateDetail;
	import common.model.WqStaffInfo;
	import common.util.CodeModelUtil;
	
	public class PointModel
	{
		public var label:String;//专给标注使用
		public var id:String;
		public var time:String;
		public var speed:String;
		public var direction:String;
		public var locDesc:String='';
		public var phone:String;
		public var depName:String;
		
		public var lng:Number; //真实经度
		public var lat:Number; //真实纬度
		
		public var offsetLng:Number;//偏移经度
		public var offsetLat:Number;//偏移纬度
		
		public var content:String;
		
		public function PointModel(lng:Number=0,lat:Number=0,id:String=null,content:String=null,locDesc:String=null){
			this.label="";
			this.id = id;
			this.lng = this.offsetLng = lng;
			this.lat = this.offsetLat = lat;
			this.locDesc = locDesc;
			this.content = content;
		}
		
		public function getContent():String{
			if(content){
				return content;
			}
			content = "";
			if(phone){
				content = content.concat("电话：").concat(phone);
			}
			if(depName){
				content = content.concat("<br>部门：").concat(depName).concat("<br>");
			}
			if(time){
				content = content.concat("<br>时间：").concat(time);
			}
			if(speed){
				content = content.concat("<br>速度：").concat(speed).concat("公里/小时");
			}
			if(locDesc){
				var locDescArr:Array = locDesc.split(";",3);
				if(locDescArr.length>=1){
					content = content.concat("<br>省市：").concat(locDescArr[0]);
				}
				if(locDescArr.length>=2){
					content = content.concat("<br>街区：").concat(locDescArr[1]);
				}
				if(locDescArr.length>=3){
					content = content.concat("<br>附近：").concat(locDescArr[2]);
				}
			}
			return content;
		}
		
		/**
		 * 通过定位信息转换
		 */
		public static function convertByDcGpsReal(p:DcGpsReal):PointModel{
			var staff:WqStaffInfo = CodeModelUtil.getWqStaffInfoByStaffId(p.tmnAlias);
			var dep:WqDepInfo = null;
			if(staff){
				dep = CodeModelUtil.getWqDepInfoByDepId(staff.depId);
			}
			
			var pm:PointModel = new PointModel(p.logit,p.lat,p.tmnAlias,null,p.locDesc);
			pm.label = staff ? staff.cnName : ""
			pm.direction = p.direction;
			pm.offsetLat = p.latOffset;
			pm.offsetLng = p.logitOffset;
			pm.time = p.reportTime;
			pm.speed = p.speed;
			pm.phone = staff ? staff.mobileNumber : "";
			pm.depName = dep ? dep.name : "";
			
			return pm;
		}
		
		/**
		 * 通过详细定位计划转换
		 */ 
		public static function convertByWqPlanLocateDetail(p:WqPlanLocateDetail):PointModel{
			var staff:WqStaffInfo = CodeModelUtil.getWqStaffInfoByStaffId(p.staffId);
			var dep:WqDepInfo = null;
			if(staff){
				dep = CodeModelUtil.getWqDepInfoByDepId(staff.depId);
			}
			
			var pm:PointModel = new PointModel(p.logit,p.lat,p.staffId,null,p.locDesc);
			pm.label = staff ? staff.cnName : ""
			pm.direction = p.direction;
			pm.offsetLat = p.latOffset;
			pm.offsetLng = p.logitOffset;
			pm.time = p.reportTime;
			pm.speed = p.speed;
			pm.phone = staff ? staff.mobileNumber : "";
			pm.depName = dep ? dep.name : "";
			return pm;
		}
		
		public function copy():PointModel{
			var pm:PointModel = new PointModel(this.lng,this.lat,this.id,this.content,this.locDesc);
			pm.offsetLng = this.offsetLng;
			pm.offsetLat = this.offsetLat;
			pm.time = this.time;
			pm.direction = this.direction;
			pm.label = this.label;
			pm.speed = this.speed;
			pm.phone = this.phone;
			pm.depName = this.depName;
			return pm;
		}
	}
}